// miniprogram/pages/Input/Input.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
    console.log(this.data.name)
  },
  sexInput: function (e) {
    this.setData({
      sex: e.detail.value
    })
    console.log(this.data.sex)
  },
  mobileInput: function (e) {
    this.setData({
      mobile: e.detail.value
    })
    console.log(this.data.mobile)
  },
  togeInput: function (e) {
    this.setData({
      toge: e.detail.value
    })
    console.log(this.data.toge)
  },
  remarksInput: function (e) {
    this.setData({
      remarks: e.detail.value
    })
    console.log(this.data.remarks)
  },
  submit: function () {
    var _ = this;
    var room_type = wx.getStorageSync('room_type')
    if (_.data.sex == '男') {
      var sex = 1
    } else {
      var sex = 2
    }
    wx.request({
      url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/trainingbase/upd_acc_info',
      method: 'POST',
      data: {
        mobile: _.data.mobile,
        name: _.data.name,
        sex: sex,
        room_pn: 4,
        room_type: room_type,
        peers: _.data.toge,
        remarks: _.data.remarks
      },
      success(res) {
        console.log(res)
        room_type == 1 ? _.setData({
          room_type: '上下床'
        }) : _.setData({
          room_type: '上床下桌'
        });
        _.setData({
          fixed: 1
        })
      }
    })
  },
  tomy: function () {
    wx.redirectTo({
      url: '../reservation/reservation',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    var sex = wx.getStorageSync('sex')
    var name = wx.getStorageSync('name')
    var mobile = wx.getStorageSync('mobile')
    if (name) {
      _.setData({
        name
      })
    }
    if (mobile) {
      _.setData({
        mobile
      })
    }
    if (sex == 1) {
      _.setData({
        sex: '男'
      })
    } else {
      _.setData({
        sex: '女'
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})